package fr.emn.integration.synthese.presentation;

import java.awt.Dimension;
import java.awt.Frame;
import java.awt.GridLayout;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;

import fr.emn.integration.synthese.abstraction.Cours;
import fr.emn.integration.synthese.abstraction.Module;
import fr.emn.integration.synthese.controle.ControlJButtonSaveModule;

public class ModuleDialog extends JDialog {

	private static final long serialVersionUID = 1L;

	private JTextField nom;
	private JTextField responsable;

	public String getNom() {
		return nom.getText();
	}
	
	public String getResponsable(){
		return responsable.getName();
	}

	public ModuleDialog(Frame parent, Cours modele, boolean creation) {
		super(parent, "Module", true);
		this.getContentPane().setLayout(new GridLayout(1, 3));
		this.setMinimumSize(new Dimension(200, 100));

		JPanel form = new JPanel(new GridLayout(5, 1));
		form.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6));

		form.add(new JLabel("Nom"));
		nom = new JTextField();
		form.add(nom);
		form.add(new JLabel("Mail Responsable"));
		responsable = new JTextField();
		form.add(responsable);
		JPanel buttons = new JPanel();
		JButton save = new JButton("OK");
		save.addActionListener(new ControlJButtonSaveModule(this, modele,
				creation));
		buttons.add(save);
		form.add(buttons);
		this.getContentPane().add(form);

		if (!creation) {
			Module courante = modele.findModule(modele.getModuleCourante());
			nom.setText(courante.getNom());
			responsable.setText(courante.getResponsable());
				
		}

		this.pack();
		super.setLocationRelativeTo(parent);
	}

}
